SHELL=cmd.exe
# make 参数
project=spring-webapp

# 环境变量
# tomcat 启动
SHELL_CATALINA_HOME=$CATALINA_HOME

catalina_home=$(shell echo $(value SHELL_CATALINA_HOME))
ifeq ($(wildcard $(catalina_home)), )
catalina_home=E:\apache-tomcat-8.0.20-windows-x64\apache-tomcat-8.0.20
export CATALINA_HOME=$(catalina_home)
endif

run_command=$(catalina_home)\bin\catalina.bat run

# maven 可执行文件
maven_bin=E:\apache-maven-3.6.3\bin\mvn

########################################
# 命令定义
########################################
all: run

test:
	@echo $(catalina_home)

package: clean
	$(maven_bin) package

copy: package
	copy target\$(project).war $(catalina_home)\webapps

run: copy
	$(run_command)

.PHONY : clean_tomcat
tomcat_app:=$(catalina_home)\webapps\$(project)
clean_tomcat:
ifneq ($(wildcard $(tomcat_app).war), )
	del /S/Q $(catalina_home)\$(project).war
endif
ifneq ($(wildcard $(tomcat_app)), )
	rmdir /Q/S $(catalina_home)\$(project)
endif

.PHONY : clean
clean: clean_tomcat
	$(maven_bin) clean